(ns ura.notify
  (:require
   [reagent.core :as r]
   [reagent.dom :as rd]
   [stylefy.core :as sty]
   [stylefy.reagent :as stylefy-reagent]
   [ajax.core :refer [GET POST DELETE]]
   [ura.common :as uc :refer [log spy]]
   [ura.style :as style :refer [attr]]
   ))



(defn notifyPane [content params node]
  (let [{title :title timeout :timeout} params ]
    (spy ["notify: " title content timeout])
    (when timeout (js/setTimeout #(js/document.body.removeChild node) timeout))
    [:div (attr
           :position=fixed :top=10px :left=0 :right=0 :z-index=99
           :w=500px :mx=auto :px=10px 
           :rounded=7px :bgc=green-300 :opacity=0.9
           [:box-shadow "0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19)"
            :transition "opacity 0.2s, top 0.2s, visibility 0.2s"
            :transition-timing-function "ease-in"
            ]
           )
     [:div (attr :flex :jc-b)
      [:span (attr :font-size=18px) title]
      [:button (attr :font-size=12px :cursor=pointer {:on-click #(js/document.body.removeChild node)}) "x"]
      ]
     
     [:div (attr :font-size=16px :mb=5px) content]
     ]
    )
  )


(defn showNotify [content & params]
  (let [ node1 (js/document.createElement "div")]
    (js/document.body.appendChild node1)
    (rd/render [notifyPane content params node1] node1)
    )
  )
